{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "arr = [3,4,5,1,1,6,5,2,1,5,5,6,3,3,5,3,1,3,1,1,6,4,1,4,3,5,5,1,3,5,5,4,6,3,5,3,6,3,1,5,1,3,3,1,1,1,4,3,2,3,1,6,6,5,4,4,4,6,3,5,4,2,4,1,2,3,3,1,3,2,2,6,6,6,2,5,5,1,5,1,6,2,3,2,2,1,3,2]\n",
    "m = 5\n",
    "k = 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[(1, 2), (1, 3), (2, 3)]"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import itertools\n",
    "\n",
    "list(itertools.combinations([1,2,3], 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[4, 5, 1, 1, 6]\n",
      "[5, 1, 1, 6, 5]\n",
      "[1, 1, 6, 5, 2]\n",
      "[1, 6, 5, 2, 1]\n",
      "[6, 5, 2, 1, 5]\n",
      "[5, 2, 1, 5, 5]\n",
      "[2, 1, 5, 5, 6]\n",
      "[1, 5, 5, 6, 3]\n",
      "[5, 5, 6, 3, 3]\n",
      "[5, 6, 3, 3, 5]\n",
      "[6, 3, 3, 5, 3]\n",
      "[3, 3, 5, 3, 1]\n",
      "[3, 5, 3, 1, 3]\n",
      "[5, 3, 1, 3, 1]\n",
      "[3, 1, 3, 1, 1]\n",
      "[1, 3, 1, 1, 6]\n",
      "[3, 1, 1, 6, 4]\n",
      "[1, 1, 6, 4, 1]\n",
      "[1, 6, 4, 1, 4]\n",
      "[6, 4, 1, 4, 3]\n",
      "[4, 1, 4, 3, 5]\n",
      "[1, 4, 3, 5, 5]\n",
      "[4, 3, 5, 5, 1]\n",
      "[3, 5, 5, 1, 3]\n",
      "[5, 5, 1, 3, 5]\n",
      "[5, 1, 3, 5, 5]\n",
      "[1, 3, 5, 5, 4]\n",
      "[3, 5, 5, 4, 6]\n",
      "[5, 5, 4, 6, 3]\n",
      "[5, 4, 6, 3, 5]\n",
      "[4, 6, 3, 5, 3]\n",
      "[6, 3, 5, 3, 6]\n",
      "[3, 5, 3, 6, 3]\n",
      "[5, 3, 6, 3, 1]\n",
      "[3, 6, 3, 1, 5]\n",
      "[6, 3, 1, 5, 1]\n",
      "[3, 1, 5, 1, 3]\n",
      "[1, 5, 1, 3, 3]\n",
      "[5, 1, 3, 3, 1]\n",
      "[1, 3, 3, 1, 1]\n",
      "[3, 3, 1, 1, 1]\n",
      "[3, 1, 1, 1, 4]\n",
      "[1, 1, 1, 4, 3]\n",
      "[1, 1, 4, 3, 2]\n",
      "[1, 4, 3, 2, 3]\n",
      "[4, 3, 2, 3, 1]\n",
      "[3, 2, 3, 1, 6]\n",
      "[2, 3, 1, 6, 6]\n",
      "[3, 1, 6, 6, 5]\n",
      "[1, 6, 6, 5, 4]\n",
      "[6, 6, 5, 4, 4]\n",
      "[6, 5, 4, 4, 4]\n",
      "[5, 4, 4, 4, 6]\n",
      "[4, 4, 4, 6, 3]\n",
      "[4, 4, 6, 3, 5]\n",
      "[4, 6, 3, 5, 4]\n",
      "[6, 3, 5, 4, 2]\n",
      "[3, 5, 4, 2, 4]\n",
      "[5, 4, 2, 4, 1]\n",
      "[4, 2, 4, 1, 2]\n",
      "[2, 4, 1, 2, 3]\n",
      "[4, 1, 2, 3, 3]\n",
      "[1, 2, 3, 3, 1]\n",
      "[2, 3, 3, 1, 3]\n",
      "[3, 3, 1, 3, 2]\n",
      "[3, 1, 3, 2, 2]\n",
      "[1, 3, 2, 2, 6]\n",
      "[3, 2, 2, 6, 6]\n",
      "[2, 2, 6, 6, 6]\n",
      "[2, 6, 6, 6, 2]\n",
      "[6, 6, 6, 2, 5]\n",
      "[6, 6, 2, 5, 5]\n",
      "[6, 2, 5, 5, 1]\n",
      "[2, 5, 5, 1, 5]\n",
      "[5, 5, 1, 5, 1]\n",
      "[5, 1, 5, 1, 6]\n",
      "[1, 5, 1, 6, 2]\n",
      "[5, 1, 6, 2, 3]\n",
      "[1, 6, 2, 3, 2]\n",
      "[6, 2, 3, 2, 2]\n",
      "[2, 3, 2, 2, 1]\n",
      "[3, 2, 2, 1, 3]\n",
      "[2, 2, 1, 3, 2]\n"
     ]
    }
   ],
   "source": [
    "for i in range(len(arr)):\n",
    "    if i < len(arr) - m+1:\n",
    "        combination = arr[i:i+m]\n",
    "        print(combination)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/detect-pattern-of-length-m-repeated-k-or-more-times\n",
    "\n",
    "\n",
    "\n",
    "Runtime: 40 ms, faster than 22.95% of Python3 online submissions for Detect Pattern of Length M Repeated K or More Times.\n",
    "Memory Usage: 14.3 MB, less than 100.00% of Python3 online submissions for Detect Pattern of Length M Repeated K or More Times.\n",
    "\n",
    "\n",
    "\n",
    "```python\n",
    "class Solution:\n",
    "    def containsPattern(self, arr: List[int], m: int, k: int) -> bool:\n",
    "        text_arr = \",\".join([str(i) for i in arr]) + \",\"\n",
    "        for i in range(len(arr)):\n",
    "            if i < len(arr) - m+1:\n",
    "                combination = arr[i:i+m]\n",
    "                if m == 1:\n",
    "                    part = str(combination[0]) + \",\"\n",
    "                else:\n",
    "                    part = \",\".join([str(i) for i in combination]) + \",\"\n",
    "                times = text_arr.count(part)\n",
    "                if times >= k:\n",
    "                    if (part * k) in text_arr:\n",
    "                        return True\n",
    "        return False\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
